package com.example.siyun.controller.permissionscontroller;

import com.example.siyun.pojo.EnumPojo;
import com.example.siyun.pojo.ManagerListBanLog;
import com.example.siyun.service.permissionsservice.ManagerlistbanlogService;
import com.example.siyun.util.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @Auther: 全
 * @Date: 2022/9/26 09:33
 * @Description:权限管理模块管理员登录的日志
 */
@Slf4j
@RestController
public class ManagerlistbanlogController {
    @Autowired
    private ManagerlistbanlogService managerlistbanlogService;
    @RequestMapping("/advanced/addmanagerlistban")
    public PageResult addCourseProcess(ManagerListBanLog managerlistbanlog, HttpSession session){
        String operatename= (String) session.getAttribute("loginname");
        managerlistbanlog.setOperatename(operatename);
        managerlistbanlogService.addManagerListBanLog(managerlistbanlog);
        managerlistbanlogService.addBanNum(managerlistbanlog.getName(),managerlistbanlog.getBannum());
        managerlistbanlogService.setState(managerlistbanlog.getName(),EnumPojo.STATE_1);
        PageResult pageResult=new PageResult();
//        pageResult.setStatus(200);
        return pageResult;
    }
    /**
     * 获取管理人员封停日志
     * @return 返回管理人员封停日志
     */
    @RequestMapping("/advanced/getmanagerbanlog")
    public PageResult getManagerBanLog(ManagerListBanLog managerlistbanlog, int page, int limit) {
        log.info("获取管理人员封停日志");
        PageHelper.startPage(page, limit);
        List<ManagerListBanLog> list = managerlistbanlogService.getManagerListBanLog(managerlistbanlog, EnumPojo.VALUE_DEL_0);
        PageInfo<ManagerListBanLog> pageInfo = new PageInfo<>(list);
        PageResult pageResult=new PageResult();
        pageResult.setState(0);
        pageResult.setMessage("成功");
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setData(pageInfo.getList());
        log.info("获取管理人员封停日志成功");
        return pageResult;
    }
    /**
     * 通过id删除对应的封停日志
     * @return id要删除的封停日志
     */
    @RequestMapping("/advanced/delmanagerlistban")
    public PageResult delManagerListBan(int id){
        log.info("通过id删除对应的封停日志");
        managerlistbanlogService.delListBan(id,EnumPojo.VALUE_DEL_1);
        PageResult pageResult=new PageResult();
//        pageResult.setStatus(200);
        log.info("通过id删除对应的封停日志成功");
        return pageResult;
    }
}
